import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-11-15
 * Time: 20:49
 */
class Message {
    public String aa;
    public String bb;
}
@WebServlet("/post")
public class ServletPost extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String s1 = req.getParameter("aa");
//        String s2 = req.getParameter("bb");
//        resp.setContentType("test/html; charset=utf8");
//        resp.getWriter().write("aa: " + s1 + "bb: " + s2);

        ObjectMapper objectMapper = new ObjectMapper();
        Message message = objectMapper.readValue(req.getInputStream(), Message.class);
        String jsonString = objectMapper.writeValueAsString(message);
        resp.setContentType("application/json; charset=utf8");
        resp.getWriter().write(jsonString);
    }
}
